package com.gitee.feizns.quickstart.ding.talk.api.v10.todo.users;

import com.aliyun.dingtalktodo_1_0.Client;
import com.aliyun.dingtalktodo_1_0.models.CreateTodoTaskHeaders;
import com.aliyun.dingtalktodo_1_0.models.CreateTodoTaskRequest;
import com.aliyun.dingtalktodo_1_0.models.CreateTodoTaskResponse;
import com.aliyun.dingtalktodo_1_0.models.CreateTodoTaskResponseBody;
import com.aliyun.teautil.models.RuntimeOptions;
import com.gitee.feizns.quickstart.ding.talk.client.Clients;
import lombok.SneakyThrows;

/**
 * 创建钉钉待办任务
 *
 * @link 创建钉钉待办任务 -> <a href="https://open.dingtalk.com/document/orgapp/add-dingtalk-to-do-task">创建钉钉待办任务</a>
 * @author feizns
 * @since 2023/09/12
 */
public class Tasks {

    /**
     * 头
     * @param accessToken 访问令牌
     * @return {@link CreateTodoTaskHeaders}
     */
    public static CreateTodoTaskHeaders headers(String accessToken) {
        CreateTodoTaskHeaders headers = new CreateTodoTaskHeaders();
        headers.setXAcsDingtalkAccessToken(accessToken);
        return headers;
    }

    /**
     * 执行
     * @param accessToken 访问令牌
     * @param operatorId 操作者编号
     * @param request 请求
     * @return {@link CreateTodoTaskResponseBody}
     */
    @SneakyThrows
    public static CreateTodoTaskResponseBody execute(String accessToken, String operatorId, CreateTodoTaskRequest request) {
        Client client = Clients.get(Client.class);
        CreateTodoTaskResponse task = client.createTodoTaskWithOptions(operatorId, request, headers(accessToken), new RuntimeOptions());
        return task.getBody();
    }

}
